<template>
  <view class="container" v-if="!loading">
    <basic :result="baziResult"></basic>
    <sizhu :result="baziResult"></sizhu>
    <activity-box :positionId="702"></activity-box>
    <view class="line">大运流年</view>
    <dayunsizhu ref="dayunsizhu" :result="baziResult" :dayun="selectedDayun" :liunian="selectedLiunian" :liuyue="selectedLiuyue" :liuri="selectedLiuri"></dayunsizhu>
    <dayun :result="baziResult" @change="changeDayun"></dayun>
    <liunian :result="baziResult" @change="changeLiunian"></liunian>
    <liuyue :result="baziResult" @change="changeLiuyue"></liuyue>
    <liuri :result="baziResult" @change="changeLiuru"></liuri>
    <liuyishensha :result="baziResult" :dayun="selectedDayun" :liunian="selectedLiunian" :liuyue="selectedLiuyue" :liuri="selectedLiuri"></liuyishensha>
    <view class="line">细盘</view>
    <xipan :result="baziResult"></xipan>
    <view class="thanks">
      <view class="thanks-name">特别鸣谢：九龙先生</view>
      <view>作为易朴特邀名师，为本排盘所提供的内容支持。</view>
    </view>
    <activity-box :positionId="703"></activity-box>
    
    <uni-popup ref="popup" type="center" :is-mask-click="false">
      <view class="pop-box">
        <image class="popup-img" mode="heightFix" :src="popInfo" />
        <image class="popup-close" mode="heightFix" src="@/static/images/bazi/close.png" @click="closePop" />
      </view>
    </uni-popup>
  </view>
</template>
<script>
  import {
    getBaziResultApi, getMallListApi
  } from "@/http/api"
  import {
    getJiulongBaziResultApi
  } from "@/http/api/jiulong.js"
  import basic from "./components/basic.vue"
  import sizhu from "./components/sizhu.vue"
  import dayunsizhu from "./components/dayunsizhu.vue"
  import dayun from "./components/dayun.vue"
  import liunian from "./components/liunian.vue"
  import liuyue from "./components/liuyue.vue"
  import liuri from "./components/liuri.vue"
  import liuyishensha from "./components/liuyishensha.vue"
  import xipan from "./components/xipan.vue"
  export default {
    components: {
      basic,
      sizhu,
      dayunsizhu,
      dayun,
      liunian,
      liuyue,
      liuri,
      liuyishensha,
      xipan
    },
    data() {
      return {
        loading: true,
        baziResult: {},
        // dayun: [],
        itemindex: 0,
        popInfo: '',
        selectedDayun: {},
        selectedLiunian: {},
        selectedLiuyue: {},
        selectedLiuri: {}
      }
    },
    methods: {
      closePop() {
        this.$refs.popup.close()
      },
      changeDayun(e) {
        this.selectedDayun = e;
      },
      changeLiunian(e) {
        this.selectedLiunian = e;
      },
      changeLiuyue(e) {
        this.selectedLiuyue = e;
      },
      changeLiuru(e) {
        this.selectedLiuri = e;
        this.$refs.dayunsizhu.changeLunarmonth(this.selectedLiuri);
      },
      onLoad(a) {
        uni.showLoading({
          mask: true,
          title: "加载中",
        });
        let {
          name,
          sex,
          area,
          year,
          month,
          day,
          hour,
          minute,
          isSolar
        } = a;
        getJiulongBaziResultApi({
          userName: name,
          birthDay: `${year}-${month}-${day} ${hour}:${minute}`,
          districtGeocode: area,
          sex: sex == "0" ? "男" : "女",
          solar: isSolar == "1",
          type: 'jiulong'
        }).then(res => {
          if (res.code == 200) {
            this.baziResult = res.data;
            uni.hideLoading();
            this.loading = false;
            getMallListApi({
              pageNum: 1,
              pageSize: 999,
              status: 1,
              category: 96,
            }).then((r) => {
              if (r.code == 200 && r.rows.length > 0) {
                let num = uni.getStorageSync('concernAppJiuLongTips') || 0;
                if (num > 2) return;
                this.$refs.popup.open();
                this.popInfo = r.rows[0].imageLinks;
                uni.setStorageSync('concernAppJiuLongTips', ++num);
              }
            })
          }else{
            uni.showToast({
              title: res.msg,
              icon: 'none'
            });
          }
        });
      }
    }
  };
</script>

<style lang="scss" scoped>
  .container {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    width: 100%;
    overflow-x: hidden;
  }
  .item-box {
    box-sizing: border-box;
    width: 100%;
  }
  .pop-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  .popup-img {
    width: 600rpx;
    height: 600rpx;
    margin-bottom: 40rpx;
  }
  .popup-close {
    width: 80rpx;
    height: 80rpx;
  }
  .line {
    width: 100%;
    text-align: center;
    color: #CC0000;
    font-size: 36rpx;
    font-weight: bold;
    padding: 30rpx 0 20rpx;
  }
  .thanks {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    margin-top: 30rpx;
  }
  .thanks-name {
    font-size: 36rpx;
  }
</style>